package sample.test.cc.cool;

import sample.test.cc.cool.gui.controllers.AgentContainerController;
import sample.test.cc.simpleagent.ReadGuard;
import sample.test.cc.simpleagent.SimpleAgent;
import sample.test.cc.simpleagent.SimpleBehavior;
import sample.test.cc.simpleagent.SimpleState;
import sample.test.cc.simpleagent.WriteGuard;
import BESA.Agent.StructBESA;
import BESA.SystemLevel.AdmBESA;

public class ResourcePublication{
    
    private AdmBESA admin;
    
    
    public ResourcePublication(){
    	try {
    		
			setAdmin(AdmBESA.getInstance());
    	}catch (UnsupportedOperationException e) {
    		AgentContainerController.getInstance().showCreateDialog();
		} catch (Exception e) {

			e.printStackTrace();
		}
    }

    public void publishAgent(String alias, int value) {
        StructBESA simpleStruct = new StructBESA();
        simpleStruct.addBehavior(SimpleBehavior.class.getName());
        simpleStruct.bindGuard(WriteGuard.class.getName(), SimpleBehavior.class.getName());
        simpleStruct.bindGuard(ReadGuard.class.getName(), SimpleBehavior.class.getName());
        SimpleState ss = new SimpleState(value);
        new SimpleAgent(alias, ss, simpleStruct, 1.0);
    }

	public void setAdmin(AdmBESA admin) {
		this.admin = admin;
	}

	public AdmBESA getAdmin() {
		if(admin==null)
			admin=AdmBESA.getInstance();
		return admin;
	}

	
}
